// ref part of String
pub fn slice() {
    println!("hello slice");
    use_slice();
    use_mut_slice();
    use_str();
    array_slice();
}

fn use_slice(){
    let s = String::from("broadcast");

    let part1: &str = &s[0..5];
    let part2: &str = &s[5..9];

    println!("{}={}+{}", s, part1, part2);
}

fn use_mut_slice(){
    let mut s = String::from("runoob");
    s.push_str("-first!"); //mutable string to push_str

    let slice: &str = &s[0..3]; // immutable borrow now
    //s.push_str("yes!"); //compile error: origin s is immutable
    println!("slice = {}", slice);
}


fn use_str(){
    let slice = "hello world";
    let s: &str = &slice[..3];
    println!("slice = [{}] substr : [{}]", slice, s);
}

fn array_slice(){
    let arr: [i32; 4] = [1, 2, 3, 4];
    let part = &arr[0..2];
    for i in part.iter(){
        println!("{}", i);
    }
}
